package com.example.myapplication.tack_15;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import com.example.myapplication.R;
import com.example.myapplication.tack_15.adapter.FenLeiAdapter;
import com.example.myapplication.tack_15.data.FenLeiData;
import com.example.myapplication.utils.OkHttpTool;

import java.util.List;

public class FenLeiXQActivity extends AppCompatActivity {
    private ImageView exit;
    private RecyclerView fenlei;
    private List<FenLeiData.RowsDTO> listFenLei;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tack_15_activity_fen_lei_x_q);
        init();
        exit_();
        getFenLei();
    }
    private void getFenLei() {
        String url = "prod-api/api/lawyer-consultation/legal-expertise/list";
        OkHttpTool.doNetRequest(url, OkHttpTool.GET, FenLeiData.class, new OkHttpTool.NetCallback() {
            @Override
            public void onSuccess(Object obj) {
                FenLeiData fenLeiData = (FenLeiData)obj;
                if(fenLeiData.getCode() == 200){
                    listFenLei = fenLeiData.getRows();
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            fenAdapter();
                        }
                    });
                }
            }

            @Override
            public void onFailure(String msg) {

            }
        });
    }

    private void fenAdapter() {
        FenLeiAdapter fenLeiAdapter = new FenLeiAdapter(listFenLei, FenLeiXQActivity.this);
        GridLayoutManager gridLayoutManager = new GridLayoutManager(FenLeiXQActivity.this,4);
        gridLayoutManager.setOrientation(GridLayoutManager.VERTICAL);
        fenlei.setAdapter(fenLeiAdapter);
        fenlei.setLayoutManager(gridLayoutManager);
    }
    private void exit_() {
        exit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                FenLeiXQActivity.this.finish();
            }
        });
    }

    private void init() {
        exit = findViewById(R.id.exit);
        fenlei = findViewById(R.id.fenlei);
    }
}